#!/usr/bin/env python

import sys
import random
import itertools
import optparse

from metrics import mutual_information

def iter_random_mi(length, n1, n2):
    s2 = set(range(n2))
    while True:
        s1 = set(random.sample(xrange(length), n1))
        n12 = len(s1.intersection(s2))
        yield mutual_information(length, n1, n2, n12)


def main():
    parser = optparse.OptionParser()
    parser.add_option(
        '-g',
        dest    = 'genomes_num',
        type    = 'int',
        default = 0,
    )
    options, args = parser.parse_args()
    genomes_num = options.genomes_num

    import gc
    gc.disable()
   
    half_genomes_num = int((genomes_num+1)/2)
    for n1 in xrange(1, half_genomes_num+1):
        for n2 in xrange(n1, half_genomes_num+1):
            l = sorted(itertools.islice(iter_random_mi(genomes_num, n1, n2), 10000))
#            print ' '.join('%.6f' % i for i in l)
            level = 0.95
            mi = l[int(len(l)*level)-1]
            print "%s,%s\t%f" % (n1, n2, mi)

if __name__ == '__main__':
    
    main()


